package com.study.ming.studydemo.thd;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;

public class StudyCallable implements Callable {
    @Override
    public Object call() throws Exception {
//        TimeUnit.SECONDS.sleep(60);
        for (int i = 0; i < 100; i++) {
            System.out.println(Thread.currentThread().getName() + "callable方式");
        }
        return Thread.currentThread().getName() + "返回值";
    }

    public static void main(String[] args) throws ExecutionException, InterruptedException {
//        final StudyCallable callable = new StudyCallable();
//        final FutureTask<String> task = new FutureTask<>(callable);
//        final Thread thread = new Thread(task);
//        thread.start();
//        final String s = task.get();
//        System.out.println("main方法结束");
        final StudyRunnable runnable = new StudyRunnable();
        final Thread thread1 = new Thread(runnable);
        thread1.start();
//        thread1.join();

        for (int i = 0; i < 1000; i++) {
            if (i == 100) {
                try {
                    synchronized (StudyCallable.class) {
                        StudyCallable.class.wait();
                    }
                } catch (Exception e) {
                }
            }
            if (i == 800) {
                try {
                    synchronized (StudyCallable.class) {
                        StudyCallable.class.notify();
                    }
                } catch (Exception e) {
                }
            }
            System.out.println(i + "  main");
        }
    }
}
